<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<link rel="stylesheet" type="text/css" href="css/common.css"/>
		<link rel="stylesheet" type="text/css" href="css/article_list.css"/>
	</head>
	<body>
		<form action="" method="post" class="search_box">
			<span>标题：<input type="text" id="title" name="title"/></span>
			<span>作者：<input type="text" id="layerName" name="layerName"/></span>
			<span>领域：
				<select name="expert" id="expert">
					<option value="">全部</option>
					<option value="婚姻继承">婚姻继承</option>
					<option value="合同纠纷">合同纠纷</option>
					<option value="民间借贷">民间借贷</option>
					<option value="人身损害">人身损害</option>
					<option value="房产纠纷">房产纠纷</option>
					<option value="建筑拆迁">建筑拆迁</option>

					<option value="刑事辩护">刑事辩护</option>
					<option value="行政案件">行政案件</option>
					<option value="知识产权">知识产权</option>
					<option value="公司法务">公司法务</option>
					<option value="劳动争议">劳动争议</option>
					<option value="专业打假">专业打假</option>

					<option value="税务律师">税务律师</option>
					<option value="金融纠纷">金融纠纷</option>
					<option value="交通事故">交通事故</option>
				</select>
			</span>
			<span>类型：
				<select name="type" id="type">
					<option value="">全部</option>
					<option value="案例">案例</option>
					<option value="学术">新闻</option>
				</select>
			</span>
				
			<button type="button" class="sub">搜索</button>
		</form>
		<div id="list_content">

		</div>

		<div class="tcdPageCode"></div>
		<script src="js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript" src="layui/layui.js"></script>
		<script src="js/jquery.page.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/jquery.cookie.js" type="text/javascript" charset="utf-8"></script>
		<script>
			jQuery.browser = {};
			(function() {
				jQuery.browser.msie = false;
				jQuery.browser.version = 0;
				if(navigator.userAgent.match(/MSIE ([0-9]+)./)) {
					jQuery.browser.msie = true;
					jQuery.browser.version = RegExp.$1;
				}
			})();

			var params = {
				name:'', //姓名
				mobile: '', //手机号
				cert: '', //执业证号
				expert: '', //领域
				limit: 20, //记录数
				offset: 1 //页码
			};
			$(document).ready(function() {
	
				search(true);//搜索
				
					//绑定搜索事件
					$(".sub").click(function() {
						params.title = $("#title").val();
						params.layerName = $("#layerName").val();
						params.type = $("#type").val();
						params.expert = $("#expert").val();
						params.offset = 1;
						search(true);
					});
				
			});
			//删除方法
			function del(id) {
				$.ajax({
					url: 'content/' + id,
					type: 'delete',
					dataType: "json",
					success: function(data) {
						if(data.rel) {
							layui.use('layer', function() {
								var layer = layui.layer;
								layer.msg('删除成功', {
									icon: 6
								})
							})
							search(false);
						}
					}
				});
			}
			//查询方法
			function search(flag) {

				$.ajax({
					url: 'content/list',
					type: 'get',
					data: params,
					dataType: "json",
					success: function(data) {
						var headTable = "<table border='0' cellspacing='0' cellpadding='0'><tr><th>ID</th><th>缩略图</th><th style='text-align: left;'>标题</th><th>作者</th>" +
							"<th>类型</th><th>发布时间</th><th>操作</th></tr>";
						var contentHtml = "";
						if(data.rows.length > 0) {
							var reg = new RegExp(",", "g");
							for(var i = 0; i < data.rows.length; i++) {
								var obj = data.rows[i];
								var index = i + 1;
//								var expert = obj.expert.replace(reg, "</span> / <span>");
								var imgHtml = "";
								if(obj.image) {
									imgHtml = "<img src='" + obj.image + "'/>";
								} else {
									imgHtml = "暂无图片";
								}
								contentHtml += "<tr><td>" + obj.id + "</td><td>" + imgHtml + "</td>" +
									"<td  style='text-align: left;'>" + obj.title + "</td><td>" + obj.layerName + "</td><td>" + obj.type + "</td>" +
									"<td>"+obj.crtTime+"</td> " +
									"<td><button id='" + obj.id + "' class='edit'>编辑</button><button id='" + obj.id + "' class='del'>删除</button></td>	</tr>";
							}
						} else {
							contentHtml = "<tr><td colspan='8'>暂无记录</td></tr>";
							$(".tcdPageCode").createPage({
											pageCount:1,
											current:1,
											backFn:function(p){

											}
									});
						}

						$("#list_content").html(headTable + contentHtml + "</table>");
						//绑定edit事件
						$(".edit").click(function() {

							var id = $(this).attr("id");
								edit(id);

						});
						//绑定删除事件
						$(".del").click(function() {
							
							var id = $(this).attr("id");
							layui.use('layer', function() {
								var layer = layui.layer;
								layer.confirm('确认删除此信息', {icon: 3},function(index){
									layer.close(index)
									del(id);
								},function(index){
									layer.close(index)
								})
							})
							/*if(confirm("确认删除此信息？")){
									del($(this).attr("id"));
							}*/
						});
						if(flag && data.rows.length > 0){
							$('.tcdPageCode').off('click');
							$(".tcdPageCode").createPage({
								pageCount: data.totalPages,
								current: data.page,
								backFn: function(p) {
									//console.log(p);
									params.offset = p;
									search(false);
								}
							});
						}
						
					}
				});
			}

			document.onkeydown = function(event){
				var e = event || window.event || arguments.callee.caller.arguments[0];
				if(e && e.keyCode == 116){
					event.preventDefault();
					
					$(window.parent.$('.showIframe').each(function(){
						if(!$(this).hasClass('hideIframe')){
							$(this).children('iframe').attr('src',$(this).children('iframe').attr('src'))
						}
					}))
				}
			}

						//删除方法
			function edit(id) {
			  $.cookie("articleId",id, { expires: 1 });
				 var text = "发布文章";
					$(window.parent.$(".acrossTab li").each(function() {
							if ($(this).children('span').text() == text) {
									$(window.parent.$("aside").attr('data-tip', 1));
									$(this).click();
							} else {
									$(window.parent.$("aside li").each(function() {
											if ($(this).text() == text) {
													$(this).click();
											}
									}));
							}
					}));



			}
		</script>
	</body>
</html>
